package com.v3admin.common.controller;

import lombok.Data;

/**
 * 通用请求响应体
 *
 * @author Junpeng.Li
 * @date 2023-12-12 09:10
 */
@Data
public class IResponse {

    /**
     * 响应状态
     */
    private Status status;

    /**
     * 响应码
     */
    private int code;

    /**
     * 消息
     */
    private String message;

    /**
     * 数据
     */
    private Object data;

    public static IResponse success(Object data) {
        return success(null, data);
    }

    public static IResponse success(String message, Object data) {
        IResponse response = new IResponse();
        response.setStatus(Status.success);
        response.setCode(200);
        response.setMessage(message == null ? "操作成功" : message);
        response.setData(data);
        return response;
    }

    public static IResponse fail(String message) {
        return fail(500, message);
    }

    public static IResponse fail(int code, String message) {
        IResponse response = new IResponse();
        response.setStatus(Status.fail);
        response.setCode(code);
        response.setMessage(message);
        return response;
    }

    enum Status {
        success, fail
    }
}
